package com.justgame.project.service.system.query;

import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.justgame.project.cloud.common.query.Column;
import com.justgame.project.cloud.common.query.BaseSelectBuilder;
import com.justgame.project.cloud.common.query.AbstractQueryWrapper;
import com.justgame.project.cloud.common.query.Query;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.justgame.project.service.system.entity.SysUserInfo;
import com.justgame.project.service.system.query.SysUserInfoQuery;
import com.justgame.project.service.system.entity.SysUserAccount;
import com.justgame.project.service.system.query.SysUserSocialInfoQuery;
import com.justgame.project.service.system.entity.SysUserInfo;
import com.justgame.project.service.system.entity.SysUserSocialInfo;
import com.justgame.project.service.system.query.SysUserAccountQuery;
import com.justgame.project.service.system.wrapper.SysUserInfoWrapper;

public class SysUserInfoQuery extends AbstractQueryWrapper<SysUserInfo, MPJLambdaWrapper<SysUserInfo>, SysUserInfoWrapper> {

    private SysUserInfoQuery() {
        super(new MPJLambdaWrapper<>(SysUserInfo.class,"sys_user_info"));
    }

    public static SysUserInfoQuery builder(){
        return new SysUserInfoQuery();
    }

    public static class Select{

        private final List<Query> queries;

        protected Select(){
            queries = new ArrayList<>();
        }

        protected Select(List<Query> queries) {
            this.queries = queries;
        }

        public Query[] getQueriesArray() {
            return queries.toArray(new Query[0]);
        }

        public static SelectBuilder builder(){
            return new SelectBuilder();
        }

        public Query[] build(){
            return queries.toArray(new Query[0]);
        }

        public static class SelectBuilder extends BaseSelectBuilder {
            public SelectBuilder SysUserInfo(){
                return SysUserInfo(Column.all());
            }

            public SelectBuilder SysUserInfo(Column column){
                return add(Query.builder(SysUserInfo.class)
                            .selectColumns(column)
                            .build());
            }

            public SelectBuilder createUser(){
                return createUser(Column.all());
            }

            public SelectBuilder createUser(Column column){
                return createUser(column, null);
            }

            public SelectBuilder createUser(Column column,SysUserInfoQuery.Select selectQuery){
                return createUser("createUserWrapper", column, null);
            }

            public SelectBuilder createUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<SysUserInfo,?>)SysUserInfo::getCreateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder updateUser(){
                return updateUser(Column.all());
            }

            public SelectBuilder updateUser(Column column){
                return updateUser(column, null);
            }

            public SelectBuilder updateUser(Column column,SysUserInfoQuery.Select selectQuery){
                return updateUser("updateUserWrapper", column, null);
            }

            public SelectBuilder updateUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<SysUserInfo,?>)SysUserInfo::getUpdateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder userSocialInfo(){
                return userSocialInfo(Column.all());
            }

            public SelectBuilder userSocialInfo(Column column){
                return userSocialInfo(column, null);
            }

            public SelectBuilder userSocialInfo(Column column,SysUserSocialInfoQuery.Select selectQuery){
                return userSocialInfo("userSocialInfoWrapper", column, null);
            }

            public SelectBuilder userSocialInfo(String mappingName,Column column,SysUserSocialInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserSocialInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserSocialInfo,?>)SysUserSocialInfo::getUserInfoId)
                            .rightOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserSocialInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder userAccount(){
                return userAccount(Column.all());
            }

            public SelectBuilder userAccount(Column column){
                return userAccount(column, null);
            }

            public SelectBuilder userAccount(Column column,SysUserAccountQuery.Select selectQuery){
                return userAccount("userAccountWrapper", column, null);
            }

            public SelectBuilder userAccount(String mappingName,Column column,SysUserAccountQuery.Select selectQuery){
                return add(Query.builder(SysUserAccount.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserAccount,?>)SysUserAccount::getUserInfoId)
                            .rightOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserAccountQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public Select build(){
                return new Select(getQueries());
            }
        }

    }
}